package com.example.demo.util;

import com.example.demo.pojo.Root;
import javassist.tools.reflect.Sample;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.input.SAXBuilder;


import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class RootUtil {
    public static List<Root> xml2RootList(String s)throws Exception {
        List<Root> S = new ArrayList<>();
        SAXBuilder sb=new SAXBuilder();
        Document doc=sb.build("file:///"+s); //构造文档对象
        Element root=doc.getRootElement(); //获取根元素
        List<Element> list=root.getChildren("root");
        for (Element value : list) {
            Root r = new Root();
            r.setName(value.getChildText("name"));
            r.setPath(value.getChildText("path"));
            S.add(r);
        }

            return S;
    }
}

